package com.huangpuweb.api.service.imp;

import com.huangpuweb.api.model.*;
import com.huangpuweb.api.service.NanDongApiService;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Service
public class NanDongApiServiceImpl extends BaseNanDongDataServiceImp implements NanDongApiService {
    @Override
    public List<NanDongUnitHouse> getNanDongUnitHouseList() {
        String sql="select * from unit_house";
        return getEntryList(sql,new NanDongUnitHouseRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongTtpInfo> getNanDongTtpInfoList() {
        String sql="select * from ttp_info";
        return getEntryList(sql,new NanDongTtpInfoRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongLwPoint> getNanDongLwPointList() {
        String sql="select * from lw_point";
        return getEntryList(sql,new NanDongLwPointRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongJzHouse> getNanDongJzHouseList() {
        String sql="select * from jz_house";
        return getEntryList(sql,new NanDongJzHouseRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongNotMoveRelic> getNanDongNotMoveRelicList() {
        String sql="select * from not_move_relic";
        return getEntryList(sql,new NanDongNotMoveRelicRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongLiHouse> getNanDongLiHouseList() {
        String sql="select * from lj_house";
        return getEntryList(sql,new NanDongLiHouseRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongHistoryArchitecture> getNanDongNanDongHistoryArchitectureList() {
        String sql="select * from history_architecture";
        return getEntryList(sql,new NanDongHistoryArchitectureRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongDjService> getNanDongDjServiceList() {
        String sql="select * from dj_service";
        return getEntryList(sql,new NanDongDjServiceRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongDfKou> getNanDongDataList() {
        String sql="select * from df_kou";
        return getEntryList(sql,new NanDongDfKouRowMapper(),new Object[]{});
    }

    @Override
    public List<NanDongCommitteeScore> getNanDongCommittee(String committee) {
        String sql="select * from committee_score where committee=?";
        return getEntryList(sql,new NanDongCommitteeScoreRowMapper(),new Object[]{committee});
    }

    @Override
    public List<NanDongAiPoint> getNanDongPoint(String type) {
        if (type.equals("all")) {
            String sql="select * from AI_point ";
            return getEntryList(sql, new NanDongAiPointRowMapper(),new Object[]{});
        }else {
            String sql = "select * from AI_point where ai_module=?";
            return getEntryList(sql, new NanDongAiPointRowMapper(), new Object[]{type});
        }
    }

    @Override
    public int getSum() {
        String sql1 = "select sum(aj_number) sum from aj_type ";
        return  queryInteger(sql1, new Object[]{});
    }

    @Override
    public List<NanDongAjType> getCountByType() {
        String sql = "select sum(aj_number) count,aj_type from aj_type  GROUP BY aj_type ";
        return getEntryList(sql, new RowMapper<NanDongAjType>() {
            @Override
            public NanDongAjType mapRow(ResultSet resultSet, int i) throws SQLException {
                NanDongAjType nd = new NanDongAjType();
                nd.setNumber(resultSet.getString("count"));
                nd.setAj_type(resultSet.getString("aj_type"));
                return nd;
            }
        }, new Object[]{});
    }

    @Override
    public List<NanDongAjType> getAjInfo(String aj_type) {
        String sql = "select * from aj_type where aj_type=?";
        return getEntryList(sql, new NanDongAjTypeRowMapper(), new Object[]{aj_type});
    }

    @Override
    public List<NanDongAjType> getAjByType() {
        String sql = "select aj_type from aj_type  GROUP BY aj_type";
        return getEntryList(sql, new RowMapper<NanDongAjType>() {
            @Override
            public NanDongAjType mapRow(ResultSet resultSet, int i) throws SQLException {
                NanDongAjType nanDongAjType = new NanDongAjType();
                nanDongAjType.setAj_type(resultSet.getString("aj_type"));
                return nanDongAjType;
            }
        }, new Object[]{});
    }

    @Override
    public void insert(String valueOf, String valueOf1, int id) {
        String sql = "update  ttp_info set lng=?,lat=? where id=? ";
        update(sql, new Object[]{valueOf, valueOf1, id});
    }

    @Override
    public List<NanDongTtpInfo> getList() {
        String sql = "select * from ttp_info";
        return getEntryList(sql, new NanDongTtpInfoRowMapper(),new Object[]{});
    }

    @Override
    public List<NdPersonInfo> getPersonInfoByType(String type) {
        String sql = "select * from person_info where type=?";
        return getEntryList(sql, new NdPersonInfoRowMapper(), new Object[]{type});
    }

    @Override
    public List<NdUnit> getNdUnitByType(String type) {
        String sql = "select * from nd_unit where unit_type=?";
        return getEntryList(sql, new NdUnitRowMapper(), new Object[]{type});
    }
}
